﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using WHC.Hotel.BLL;
using System.Drawing.Printing;

namespace WHC.Hotel.UI.Controls
{
    public partial class FrmPosPrintPreview : Form
    {
        private MultipadPrintDocument _printdocument = new MultipadPrintDocument();
        public string PrintString = "";
        private Font printFont = new Font("宋体", Convert.ToSingle(SystemConfig.Default.USBPOSFontSize));

        public FrmPosPrintPreview()
        {
            InitializeComponent();
        }

        private void FrmPosPrintPreview_Load(object sender, EventArgs e)
        {
            this.txtContent.Text = PrintString;
            this._printdocument.Text = this.txtContent.Text;
            this._printdocument.Font = printFont;
            this._printdocument.DefaultPageSettings.Landscape = SystemConfig.Default.POSPrinterLandscape;//默认纵向
            int posMargin = SystemConfig.Default.POSPageMargin;
            this._printdocument.DefaultPageSettings.Margins = new Margins(posMargin, posMargin, posMargin, posMargin);
            this._printdocument.PrinterSettings.PrinterName = SystemConfig.Default.POSPrinterName;//"GP-5860III";
        }
        private void btnPrintSetup_Click(object sender, EventArgs e)
        {
            PageSetupDialog psd = new PageSetupDialog();
            psd.Document = _printdocument;
            psd.PageSettings.Margins = PrinterUnitConvert.Convert(psd.PageSettings.Margins,
                PrinterUnit.ThousandthsOfAnInch, PrinterUnit.HundredthsOfAMillimeter);

            if (psd.ShowDialog() == DialogResult.OK)
            {
                _printdocument.Print();
            }
            else
            {
                psd.PageSettings.Margins = PrinterUnitConvert.Convert(psd.PageSettings.Margins,
                    PrinterUnit.HundredthsOfAMillimeter, PrinterUnit.ThousandthsOfAnInch);
            }
        }

        private void btnPreview_Click(object sender, EventArgs e)
        {
            PrintPreviewDialog ppd = new PrintPreviewDialog();
            _printdocument.Text = this.txtContent.Text;
            _printdocument.Font = printFont;
            ppd.Document = _printdocument;
            ppd.ShowDialog();
        }

        private void btnPrint_Click(object sender, EventArgs e)
        {
            PrintDialog pd = new PrintDialog();
            _printdocument.Text = this.txtContent.Text;
            _printdocument.Font = printFont;
            pd.Document = _printdocument;
            if (pd.ShowDialog() == DialogResult.OK)
            {
                _printdocument.Print();
            }
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
